<?php
/**
 * Created by PhpStorm.
 * User: Z
 * Date: 2017/3/30
 * Time: 11:21
 * 获取收件人标签等信息
 */

$params = array_merge( $_GET, $_POST );

if( isset( $params['Uid'] ) && !empty( $params['Uid'] ) && isset( $params['RecipientMobile'] ) && ! empty( $params['RecipientMobile'] ) )
{
    //初始化redis
    $redis = initRedis();

    if( $redis )
    {
        //收件人 redis 数据库
        $redis ->select(3);

        //获取redis数据
        $RecipientData = $redis ->HgetAll( "recipient_label_{$params['RecipientMobile']}_{$params['Uid']}" );

        if( ! empty( $RecipientData ) )
        {
            $RecipientData['label'] = json_decode( $RecipientData['label'] );

            //输出
            outPut( 1, '请求成功!', $RecipientData );
        }

        outPut( 0, '没有数据!' );
    }

    outPut( 0, '系统错误!' );
}

outPut( 0, '参数错误!' );

/**
 * Function outPut
 * @param int $code
 * @param string $msg
 * @param array $data
 *
 * Author: 黄盖
 * Date: 2017-3-30 11:35
 * Info: json输出
 */
function outPut( $code = 1, $msg = '请求成功', $data = Array() )
{
    echo json_encode( Array( 'code' => strval( $code ), 'msg' => $msg, 'data' => $data ) );
    exit;
}

/**
 * Function initRedis
 *
 * Author: 黄盖
 * Date: 2017-3-30 11:40
 * Info: 实例化redis
 */
function initRedis()
{
    if( class_exists( 'redis' ) )
    {
        $Redis = new \redis();

        if( $Redis ->connect( '10.23.218.220', 6379 ) )
        {
            return $Redis;
        }
    }

    return false;
}